package fr.nekloth.android.hinode;


import java.util.Date;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
//import android.os.PowerManager;
import android.widget.Toast;

public class alarmReceiver extends BroadcastReceiver {

//	private static PowerManager.WakeLock lockStatic=null;
	public static final String LOCK_NAME_STATIC="fr.nekloth.android.idealight";

	
	@Override
	public void onReceive(Context context, Intent intent) {
		try {
		    Intent intentToLaunch = new Intent();		    
			intentToLaunch.setClass(context, alarmReceiverDisplay.class);
			intentToLaunch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			
			
			context.startActivity(intentToLaunch);

			int mode = Activity.MODE_PRIVATE;
	    	SharedPreferences mySharedPreferences = context.getSharedPreferences("hinode_application_settings",mode);

	    	try {
		    	Date refDate = new Date();
		    	int referenceTime = (refDate.getHours() * 100) + refDate.getMinutes();
		    	SharedPreferences.Editor editor = mySharedPreferences.edit();
		    	editor.putInt ("triggerTime", referenceTime);
		    	editor.commit();
	   	    	} catch (Exception e) {
	    	}
			
		}
		catch (Exception r) {
			Toast.makeText(context, "Erreur ( " + r.getMessage() + ")",Toast.LENGTH_SHORT).show();
		}
		
	}	
	
}
